package cn.gdut.chengcai.controller;

import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.gdut.chengcai.base.ConstantUtil;

@Controller
@RequestMapping("/member")
public class MemberController {

	/**
	 * 账户待激活页
	 */
	@RequestMapping("/auth/waitingActivate")
	public String waitingActivate(ModelMap map, HttpSession session) {
		// String userActived = AccountUtil.getFromSession(session,
		// ConstantUtil.STR_USER_ACTIVED);
		String userActived = (String) session.getAttribute(ConstantUtil.STR_USER_ACTIVED);
		if (StringUtils.isEmpty(userActived) == false && userActived.equals("true")) {
			return "redirect:/member/account/baseInfo.html";
		} else {
			return "/personal/auth/waitingActivate";
		}
	}
	/*
		public static LogUtil log = LogUtil.getInstance(MemberController.class.getName());
	
		@Autowired
		protected TeacherInfoService teacherInfoService;
	
		@Autowired
		protected TeacherJoinLessonService teacherJoinLessonService;
	
		@Autowired
		protected CompanyInfoService companyInfoService;
	
		@Autowired
		protected PersonalInfoService personalInfoService;
	
		@Autowired
		protected MemberInfoService memberInfoService;
	
		@Autowired
		protected WalletInfoService walletInfoService;
	
		@Autowired
		protected AuditProcessLogService auditProcessLogService;
	
		@Autowired
		protected PersonalApplyInfoLogService personalApplyInfoLogService;
	
		@Autowired
		protected CompanyApplyInfoLogService companyApplyInfoLogService;
	
		@Autowired
		protected TeacherApplyInfoLogService teacherApplyInfoLogService;
	
		@Autowired
		protected PersonalMessageService personalMessageService;
	
		*//**
			 * 会员侧边栏重定向
			 */
	/*
	@RequestMapping("/redirect")
	public String redirect(HttpServletRequest request, HttpSession session) {
	String url = RequestUtil.getParameter(request, ConstantUtil.SESSION_SIDEBAR_URI);
	session.setAttribute(ConstantUtil.SESSION_SIDEBAR_URI, url);
	session.setAttribute(ConstantUtil.SESSION_MENUBAR_URI, null);
	return "redirect:" + url;
	}
	
	*//**
		 * 首页
		 */
	/*
	@RequestMapping("/index")
	public String index(HttpSession session, ModelMap map) {
	return "redirect:/member/redirect.html?sidebarUri=/member/career/mine/list.html";
	}
	
	*//**
		 * 保存成功页
		 */
	/*
	@RequestMapping("/saveSuccess")
	public String saveSuccess(HttpSession session, ModelMap map) {
	String returnUrl = (String) session.getAttribute(ConstantUtil.SESSION_RETURN_URL);
	session.removeAttribute(ConstantUtil.SESSION_RETURN_URL);
	map.put(ConstantUtil.SESSION_RETURN_URL, returnUrl);
	return "/member/common/saveSuccess";
	}
	
	*//**
		 * 保存失败页
		 */
	/*
	@RequestMapping("/saveFailure")
	public String saveFailure(HttpSession session, ModelMap map) {
	String returnUrl = (String) session.getAttribute(ConstantUtil.SESSION_RETURN_URL);
	session.removeAttribute(ConstantUtil.SESSION_RETURN_URL);
	map.put(ConstantUtil.SESSION_RETURN_URL, returnUrl);
	return "/member/common/saveFailure";
	}
	
	*//**
		 * 基本信息页
		 */
	/*
	@RequestMapping("/mine/info")
	public String info(HttpSession session, ModelMap map) {
	Long uid = AccountUtil.getUidFromSession(session);
	Integer type = AccountUtil.getUserTypeFromSession(session);
	
	map.put(ConstantUtil.MODEL_MAP_UPLOADFILE_TYPE, UploadFileType.SYSTEM_FILE.getValue());
	
	MemberInfo memberInfo = memberInfoService.findById(uid);
	
	if (type.intValue() == MemberType.MEMBER_COMPANY.getValue()) {
		CompanyInfo entity = companyInfoService.findById(uid);
		CompanyInfoVo vo = new CompanyInfoVo();
		if (entity != null) {
			MemberUtil.fillCompanyInfoVo(vo, memberInfo, entity);
			map.put("entity", vo);
		}
		return "/member/mine/companyInfo";
	} else {
		PersonalInfo entity = personalInfoService.findById(uid);
		PersonalInfoVo vo = new PersonalInfoVo();
		if (entity != null) {
			MemberUtil.fillPersonalInfoVo(vo, memberInfo, entity);
			map.put("entity", vo);
		}
		return "/member/mine/personalInfo";
	}
	}
	
	*//**
		 * 完善个人基本信息操作
		 */
	/*
	@RequestMapping("/mine/info/personal/saveAction")
	@ResponseBody
	public ResponseData<Object> savePersonalInfoAction(@RequestBody String jsonString, HttpServletRequest request,
		HttpSession session, ModelMap map) {
	ResponseData<Object> result = new ResponseData<>();
	result.setIsSuccess(false);
	try {
		PersonalInfo entity = JsonUtil.fromJson(jsonString, PersonalInfo.class);
		personalInfoService.updateById(entity);
	
		session.setAttribute(ConstantUtil.SESSION_RETURN_URL, "/member/mine/info.html");
		result.setIsSuccess(true);
	} catch (Exception e) {
		result.setMessage(ErrorMessageUtil.SYSTEM_ERROR);
		log.error(e.getMessage(), e);
	}
	return result;
	}
	
	*//**
		 * 完善企业基本信息操作
		 */
	/*
	@RequestMapping("/mine/info/company/saveAction")
	public String saveCompanyInfoAction(HttpServletRequest request, HttpSession session) {
	CompanyInfo entity = companyInfoService.findById(AccountUtil.getUidFromSession(session));
	int licenseType = Integer.parseInt(RequestUtil.getParameter(request, "licenseType"));
	String operatingPeriod = RequestUtil.getParameter(request, "operatingPeriod").replace("-", "");
	String certificateValidityPeriod = RequestUtil.getParameter(request, "certificateValidityPeriod").replace("-",
			"");
	
	// 获取参数
	entity.setCompanyName(RequestUtil.getParameter(request, "companyName"));
	entity.setCompanySize(StringUtils.getInteger(RequestUtil.getParameter(request, "companySize")));
	entity.setCompanyType(StringUtils.getInteger(RequestUtil.getParameter(request, "companyType")));
	entity.setProvince(RequestUtil.getParameter(request, "province"));
	entity.setCity(RequestUtil.getParameter(request, "city"));
	entity.setDistrict(RequestUtil.getParameter(request, "district"));
	entity.setStreet(RequestUtil.getParameter(request, "street"));
	entity.setOfficePhone(RequestUtil.getParameter(request, "officePhone"));
	entity.setLicenseType(licenseType);
	entity.setRegistrationMark(RequestUtil.getParameter(request, "registrationMark"));
	// entity.setOperatingPeriod(Integer.parseInt(operatingPeriod));
	entity.setBusinessScope(RequestUtil.getParameter(request, "businessScope"));
	entity.setOrganizationCode(RequestUtil.getParameter(request, "organizationCode"));
	entity.setCorporationLocation(RequestUtil.getParameter(request, "corporationLocation"));
	entity.setCorporationName(RequestUtil.getParameter(request, "corporationName"));
	entity.setCorporationIdCardNum(RequestUtil.getParameter(request, "corporationIdCardNum"));
	// entity.setCertificateValidityPeriod(Integer.parseInt(certificateValidityPeriod));
	
	// 上传处理
	Map<Integer, UploadInfoEntity> map = UploadDownloadUtil.uploadAction(request, session,
			UploadFileType.PROFILE.getValue(), entity.getCreateTime());
	if (null != map && map.size() != 0) {
	
		String filename = "";
		if (StringUtils.isEmpty(map.get(1)) == false) {
			filename = entity.getBusinessLicenceUrl();
			if (StringUtils.isEmpty(filename) == false) {
				UploadDownloadUtil.deleteAction(filename);
			}
			entity.setBusinessLicenceUrl(map.get(1).getFileUrl());
		}
		
		 * if (StringUtils.isEmpty(map.get(2)) == false) { filename =
		 * entity.getOrganizationCodeUrl(); if
		 * (StringUtils.isEmpty(filename) == false) {
		 * UploadDownloadUtil.deleteAction(filename, request); }
		 * entity.setOrganizationCodeUrl(map.get(2).getFileUrl()); }
		 
		if (StringUtils.isEmpty(map.get(3)) == false) {
			filename = entity.getBankLicenceUrl();
			if (StringUtils.isEmpty(filename) == false) {
				UploadDownloadUtil.deleteAction(filename);
			}
			entity.setBankLicenceUrl(map.get(3).getFileUrl());
		}
		
		 * if (StringUtils.isEmpty(map.get(4)) == false) { filename =
		 * entity.getIdentityCardUrl(); if (StringUtils.isEmpty(filename) ==
		 * false) { UploadDownloadUtil.deleteAction(filename, request); }
		 * entity.setIdentityCardUrl(map.get(4).getFileUrl()); }
		 
	}
	
	if (entity.getLicenseType().equals(2)) {
		
		 * UploadDownloadUtil.deleteAction(entity.getOrganizationCodeUrl(),
		 * request); entity.setOrganizationCodeUrl("");
		 * UploadDownloadUtil.deleteAction(entity.getBankLicenceUrl(),
		 * request); entity.setBankLicenceUrl("");
		 
	}
	
	// 保存数据库
	companyInfoService.updateById(entity);
	
	session.setAttribute(ConstantUtil.SESSION_RETURN_URL, "/member/mine/info.html");
	return "redirect:/member/saveSuccess.html";
	}
	
	*//**
		 * 修改密码页
		 */
	/*
	@RequestMapping("/mine/modifyPassword")
	public String modifyPassword(HttpSession session, ModelMap map) {
	Long uid = AccountUtil.getUidFromSession(session);
	if (uid != null) {
		MemberInfo entity = memberInfoService.findById(uid);
		map.put("entity", entity);
	}
	return "/member/mine/modifyPassword";
	}
	
	*//**
		 * 修改昵称操作
		 */
	/*
	@RequestMapping("/mine/modifyNicknameAction")
	@ResponseBody
	public ResponseData<Object> modifyNicknameAction(@RequestBody String jsonString, HttpServletRequest request,
		HttpSession session, ModelMap map) {
	
	ResponseData<Object> result = new ResponseData<>();
	result.setIsSuccess(false);
	
	MemberInfo param = JsonUtil.fromJson(jsonString, MemberInfo.class);
	
	try {
		MemberInfo entity = memberInfoService.findById(param.getId());
		entity.setNickname(param.getNickname());
		memberInfoService.updateById(entity);
		result.setIsSuccess(true);
	} catch (Exception e) {
		result.setMessage(ErrorMessageUtil.SYSTEM_ERROR);
		log.error(e.getMessage(), e);
	}
	return result;
	}
	
	*//**
		 * 讲师首页
		 */
	/*
	@RequestMapping("/lecturer/index")
	public String lecturerIndex() {
	return "/member/lecturer/index";
	}
	
	*//**
		 * 讲师课程管理
		 */
	/*
	@RequestMapping("/lecturer/supervise")
	public String lecturerSupervise() {
	return "/member/lecturer/supervise";
	}
	
	*//**
		 * 讲师上传课程页面
		 */
	/*
	@RequestMapping("/lecturer/upload")
	public String lecturerUpload() {
	return "/member/lecturer/upload";
	}
	
	*//**
		 * 讲师上传课程详情页面
		 */
	/*
	@RequestMapping("/lecturer/detail")
	public String lecturerDetail() {
	return "/member/lecturer/detail";
	}
	
	*//**
		 * 选择会员类型页
		 */
	/*
	@RequestMapping("/auth/selectMemberType")
	public String selectMemberType(HttpSession session, ModelMap map) {
	String userType = AccountUtil.getFromSession(session, ConstantUtil.STR_USER_TYPE);
	if (userType == null || userType.length() == 0) {
		return "/member/auth/selectMemberType";
	} else {
		return "redirect:/member/index.html";
	}
	}
	
	*//**
		 * 选择会员类型操作
		 */
	/*
	@RequestMapping(value = "/auth/selectMemberTypeAction", method = RequestMethod.POST)
	@ResponseBody
	public ResponseData<Object> selectMemberTypeAction(@RequestBody String jsonString, HttpServletRequest request,
		HttpSession session) {
	ResponseData<Object> result = new ResponseData<>();
	result.setMessage(ErrorMessageUtil.SYSTEM_ERROR);
	result.setIsSuccess(false);
	
	MemberInfoVo param = JsonUtil.fromJson(jsonString, MemberInfoVo.class);
	
	try {
		// 根据用户Sn找到记录
		MemberInfo entity = memberInfoService.findBySn(AccountUtil.getUserSnFromSession(session));
		if (entity != null) {
			if (entity.getType() != null) {
				result.setMessage(ErrorMessageUtil.MEMBER_TYPE_IS_EXIST_ERROR);
				return result;
			}
	
			int type = MemberType.getInteger(param.getType());
			if (type == MemberType.MEMBER_PERSONAL.getValue()) { // 如果注册类型是个人会员，需要添加到personal表
				PersonalInfo personalInfo = new PersonalInfo();
				personalInfo.setId(entity.getId());
				personalInfo.setSn(entity.getSn());
				personalInfo.setCreateTime(new Date());
				personalInfoService.insert(personalInfo);
	
			} else if (type == MemberType.MEMBER_COMPANY.getValue()) { // 如果注册类型是企业会员，需要添加到company表
				CompanyInfo companyInfo = new CompanyInfo();
				companyInfo.setId(entity.getId());
				companyInfo.setSn(entity.getSn());
				companyInfo.setCreateTime(new Date());
				companyInfoService.insert(companyInfo);
			} else if (type == MemberType.MEMBER_TEACHER.getValue()) { // 如果注册类型是讲师会员，需要添加到teacher表
				TeacherInfo teacherInfo = new TeacherInfo();
				teacherInfo.setId(entity.getId());
				teacherInfo.setSn(entity.getSn());
				teacherInfo.setCreateTime(new Date());
				teacherInfoService.insert(teacherInfo);
			}
			entity.setType(type);
			memberInfoService.updateById(entity);
	
			// 插入钱包信息
			WalletInfo walletInfo = new WalletInfo();
			walletInfo.setMemberId(entity.getId());
			walletInfo.setBalance(0L);
			walletInfo.setStarCoin(0L);
			walletInfo.setMemberUsername(entity.getUsername());
			walletInfo.setCreateTime(new Date());
			walletInfo.setPayPassword(entity.getPassword());// 默认支付密码即会员登录密码
			walletInfoService.insert(walletInfo);
	
			AuthController.initSession(session, entity);
	
			result.setIsSuccess(true);
		}
	} catch (Exception e) {
		result.setMessage(ErrorMessageUtil.SYSTEM_ERROR);
		log.error(e.getMessage(), e);
	}
	return result;
	}
	
	*//**
		 * 首次信息认证页
		 */
	/*
	@RequestMapping("/auth/info/first")
	public String authInfoFirst(HttpSession session, ModelMap map) {
	MemberInfo memberInfo = memberInfoService.findById(AccountUtil.getUidFromSession(session));
	if (memberInfo == null) {// 重定向到登录页
		return "redirect:/login.html";
	}
	if (memberInfo.getType() == null) {
		return "redirect:/member/auth/selectMemberType.html";
	} else {
		AuthController.initSession(session, memberInfo);
	
		int status = memberInfo.getStatus().intValue();
		if (status == MemberStatus.WAIT_AUTH_AUDIT.getValue()) {
			return "/member/auth/authAuditing";
		} else if (status == MemberStatus.AUTH_AUDIT_FAIL.getValue()) {
			return "/member/auth/authAuditFailure";
		} else if (status == MemberStatus.WAIT_AUTH.getValue()) {
			map.put(ConstantUtil.MODEL_MAP_UPLOADFILE_TYPE, UploadFileType.APPLY.getValue());
			int type = memberInfo.getType().intValue();
			if (type == MemberType.MEMBER_PERSONAL.getValue()) {
				return "/member/auth/personal";
			} else if (type == MemberType.MEMBER_COMPANY.getValue()) {
				return "/member/auth/company";
			} else if (type == MemberType.MEMBER_TEACHER.getValue()) {
				return "/member/auth/teacher";
			}
		}
	}
	return "redirect:/member/index.html";
	}
	
	*//**
		 * 重新信息认证页
		 */
	/*
	@RequestMapping("/auth/info/again")
	public String authInfoAgain(HttpSession session, ModelMap map) {
	
	MemberInfo memberInfo = memberInfoService.findById(AccountUtil.getUidFromSession(session));
	map.put(ConstantUtil.MODEL_MAP_UPLOADFILE_TYPE, UploadFileType.APPLY.getValue());
	int type = memberInfo.getType().intValue();
	if (type == MemberType.MEMBER_PERSONAL.getValue()) {
		return "/member/auth/personal";
	} else if (type == MemberType.MEMBER_COMPANY.getValue()) {
		return "/member/auth/company";
	} else if (type == MemberType.MEMBER_TEACHER.getValue()) {
		return "/member/auth/teacher";
	}
	return "redirect:/member/index.html";
	}
	
	*//**
		 * 个人信息认证操作
		 */
	/*
	@RequestMapping("/auth/personal/saveAction")
	@ResponseBody
	public ResponseData<Object> authPersonalInfoAction(HttpServletRequest request, HttpSession session) {
	ResponseData<Object> result = new ResponseData<>();
	result.setMessage(ErrorMessageUtil.SYSTEM_ERROR);
	result.setIsSuccess(false);
	try {
		MemberInfo member = memberInfoService.findBySn(AccountUtil.getUserSnFromSession(session));
		// 获取并设置参数,更新会员状态
		member.setStatus(MemberStatus.WAIT_AUTH_AUDIT.getValue());
		member.setAuditStatus(MemberStatus.WAIT_AUTH_AUDIT.getValue());
	
		PersonalApplyInfoLog log = new PersonalApplyInfoLog();
		log.setSn(member.getSn());
		log.setMobile(RequestUtil.getParameter(request, "mobile"));
		log.setIdCardName(RequestUtil.getParameter(request, "idCardName"));
		log.setIdCardNo(RequestUtil.getParameter(request, "idCardNo"));
		log.setSchool(RequestUtil.getParameter(request, "school"));
		log.setEducationalBackground(Integer.parseInt(RequestUtil.getParameter(request, "educationalBackground")));
		log.setMajor(RequestUtil.getParameter(request, "major"));
		log.setEmploymentDirection(Integer.parseInt(RequestUtil.getParameter(request, "employmentDirection")));
		log.setGrade(Integer.parseInt(RequestUtil.getParameter(request, "grade")));
		log.setWorkTime(RequestUtil.getParameter(request, "workTime"));
		log.setAuditStatus(member.getAuditStatus());
		Date createTime = new Date();
	
		if (RequestUtil.getParameter(request, "sex") != null) {
			if (RequestUtil.getParameter(request, "sex").equals("1")) {
				log.setSex("男");
			} else {
				log.setSex("女");
			}
		}
	
		// 上传处理
		Map<Integer, UploadInfoEntity> map = UploadDownloadUtil.uploadAction(request, session,
				UploadFileType.APPLY.getValue(), createTime);
		if (null != map && map.size() != 0) {
			String filename = "";
			if (StringUtils.isEmpty(map.get(1)) == false) {
				filename = log.getIdCardFrontUrl();
				if (StringUtils.isEmpty(filename) == false) {
					UploadDownloadUtil.deleteAction(filename);
				}
				log.setIdCardFrontUrl(map.get(1).getFileUrl());
			}
			if (StringUtils.isEmpty(map.get(2)) == false) {
				filename = log.getIdCardBackUrl();
				if (StringUtils.isEmpty(filename) == false) {
					UploadDownloadUtil.deleteAction(filename);
				}
				log.setIdCardBackUrl(map.get(2).getFileUrl());
			}
			if (StringUtils.isEmpty(map.get(3)) == false) {
				filename = log.getPersonalHandheldIdCardUrl();
				if (StringUtils.isEmpty(filename) == false) {
					UploadDownloadUtil.deleteAction(filename);
				}
				// map.get(3).getCreateTime();
				log.setPersonalHandheldIdCardUrl(map.get(3).getFileUrl());
			}
		}
		log.setCreateTime(createTime);
	
		// 新增审核流程
		AuditProcessLog auditProcessLog = new AuditProcessLog();
		auditProcessLog.setName(AuditStatus.getString(AuditStatus.WAIT_AUDIT.getValue()));
		auditProcessLog.setType(AuditStatus.WAIT_AUDIT.getValue());
		auditProcessLog.setSort(1);
		auditProcessLog.setTargetSn(member.getSn());
		auditProcessLog.setTargetType(AuditProcessType.PERSONAL_INFO.getValue());
		auditProcessLog.setAuditStatus(AuditStatus.WAIT_AUDIT.getValue());
		auditProcessLog.setCreateTime(createTime);
		auditProcessLogService.insert(auditProcessLog);
	
		// 保存数据库
		memberInfoService.updateById(member);
		personalApplyInfoLogService.insert(log);
	
		session.setAttribute(ConstantUtil.SESSION_RETURN_URL, "/member/auth/authAuditing.html");
		AuthController.initSession(session, member);
		result.setIsSuccess(true);
	} catch (Exception e) {
		result.setMessage(ErrorMessageUtil.SYSTEM_ERROR);
		log.error(e.getMessage(), e);
	}
	return result;
	}
	
	*//**
		 * 企业信息认证操作
		 */
	/*
	@RequestMapping("/auth/company/saveAction")
	@ResponseBody
	public ResponseData<Object> authCompanyInfoAction(HttpServletRequest request, HttpSession session) {
	
	ResponseData<Object> result = new ResponseData<>();
	result.setMessage(ErrorMessageUtil.SYSTEM_ERROR);
	result.setIsSuccess(false);
	try {
		MemberInfo member = memberInfoService.findBySn(AccountUtil.getUserSnFromSession(session));
		// 获取并设置参数,更新会员状态
		member.setStatus(MemberStatus.WAIT_AUTH_AUDIT.getValue());
		member.setAuditStatus(MemberStatus.WAIT_AUTH_AUDIT.getValue());
	
		CompanyApplyInfoLog log = new CompanyApplyInfoLog();
		log.setSn(member.getSn());
		log.setCompanyName(RequestUtil.getParameter(request, "companyName"));
		log.setCompanySize(Integer.parseInt(RequestUtil.getParameter(request, "companySize")));
		log.setCompanyType(Integer.parseInt(RequestUtil.getParameter(request, "companyType")));
		log.setOfficePhone(RequestUtil.getParameter(request, "officePhone"));
		log.setRegistrationMark(RequestUtil.getParameter(request, "registrationMark"));
		log.setOrganizationCode(RequestUtil.getParameter(request, "organizationCode"));
		log.setLicenseType(Integer.parseInt(RequestUtil.getParameter(request, "licenseType")));
		log.setOperatingBeginPeriod(Integer.parseInt(RequestUtil.getParameter(request, "operatingBeginPeriod")));
		log.setOperatingEndPeriod(Integer.parseInt(RequestUtil.getParameter(request, "operatingEndPeriod")));
		log.setCorporationName(RequestUtil.getParameter(request, "corporationName"));
		log.setCorporationIdCardNum(RequestUtil.getParameter(request, "corporationIdCardNum"));
		log.setOperatorName(RequestUtil.getParameter(request, "operatorName"));
		log.setOperatorIdCardNum(RequestUtil.getParameter(request, "operatorIdCardNum"));
		log.setOperatorValidityBeginPeriod(
				Integer.parseInt(RequestUtil.getParameter(request, "operatorValidityBeginPeriod")));
		log.setOperatorValidityEndPeriod(
				Integer.parseInt(RequestUtil.getParameter(request, "operatorValidityEndPeriod")));
		log.setProvince(RequestUtil.getParameter(request, "province"));
		log.setCity(RequestUtil.getParameter(request, "city"));
		log.setDistrict(RequestUtil.getParameter(request, "district"));
		log.setStreet(RequestUtil.getParameter(request, "street"));
		log.setAuditStatus(member.getAuditStatus());
		Date createTime = new Date();
	
		// 上传处理
		Map<Integer, UploadInfoEntity> map = UploadDownloadUtil.uploadAction(request, session,
				UploadFileType.APPLY.getValue(), createTime);
		if (null != map && map.size() != 0) {
	
			String filename = "";
			if (StringUtils.isEmpty(map.get(1)) == false) {
				filename = log.getBusinessLicenceUrl();
				if (StringUtils.isEmpty(filename) == false) {
					UploadDownloadUtil.deleteAction(filename);
				}
				log.setBusinessLicenceUrl(map.get(1).getFileUrl());
			}
			if (StringUtils.isEmpty(map.get(2)) == false) {
				filename = log.getBankLicenceUrl();
				if (StringUtils.isEmpty(filename) == false) {
					UploadDownloadUtil.deleteAction(filename);
				}
				log.setBankLicenceUrl(map.get(2).getFileUrl());
			}
			if (StringUtils.isEmpty(map.get(3)) == false) {
				filename = log.getOperatorIdCardFrontUrl();
				if (StringUtils.isEmpty(filename) == false) {
					UploadDownloadUtil.deleteAction(filename);
				}
				log.setOperatorIdCardFrontUrl(map.get(3).getFileUrl());
			}
			if (StringUtils.isEmpty(map.get(4)) == false) {
				filename = log.getOperatorIdCardBackUrl();
				if (StringUtils.isEmpty(filename) == false) {
					UploadDownloadUtil.deleteAction(filename);
				}
				log.setOperatorIdCardBackUrl(map.get(4).getFileUrl());
			}
			if (StringUtils.isEmpty(map.get(5)) == false) {
				filename = log.getOperatorHandheldIdCardUrl();
				if (StringUtils.isEmpty(filename) == false) {
					UploadDownloadUtil.deleteAction(filename);
				}
				log.setOperatorHandheldIdCardUrl(map.get(5).getFileUrl());
			}
	
		}
		log.setCreateTime(createTime);
	
		// 新增审核流程
		AuditProcessLog auditProcessLog = new AuditProcessLog();
		auditProcessLog.setName(AuditStatus.getString(AuditStatus.WAIT_AUDIT.getValue()));
		auditProcessLog.setType(AuditStatus.WAIT_AUDIT.getValue());
		auditProcessLog.setSort(1);
		auditProcessLog.setTargetSn(member.getSn());
		auditProcessLog.setTargetType(AuditProcessType.COMPANY_INFO.getValue());
		auditProcessLog.setAuditStatus(AuditStatus.WAIT_AUDIT.getValue());
		auditProcessLog.setCreateTime(createTime);
		auditProcessLogService.insert(auditProcessLog);
	
		// 保存数据库
		memberInfoService.updateById(member);
		companyApplyInfoLogService.insert(log);
		session.setAttribute(ConstantUtil.SESSION_RETURN_URL, "/member/auth/authAuditing.html");
		AuthController.initSession(session, member);
		result.setIsSuccess(true);
	} catch (Exception e) {
		result.setMessage(ErrorMessageUtil.SYSTEM_ERROR);
		log.error(e.getMessage(), e);
	}
	return result;
	
	}
	
	*//**
		 * 讲师信息认证操作
		 *//*
		@RequestMapping("/auth/teacher/saveAction")
		@ResponseBody
		public ResponseData<Object> authTeacherInfoAction(HttpServletRequest request, HttpSession session) {
		
		ResponseData<Object> result = new ResponseData<>();
		result.setMessage(ErrorMessageUtil.SYSTEM_ERROR);
		result.setIsSuccess(false);
		try {
			MemberInfo member = memberInfoService.findBySn(AccountUtil.getUserSnFromSession(session));
			// 获取并设置参数,更新会员状态
			member.setStatus(MemberStatus.WAIT_AUTH_AUDIT.getValue());
			member.setAuditStatus(MemberStatus.WAIT_AUTH_AUDIT.getValue());
		
			TeacherApplyInfoLog log = new TeacherApplyInfoLog();
			log.setSn(member.getSn());
			log.setMobile(RequestUtil.getParameter(request, "mobile"));
			log.setIdCardName(RequestUtil.getParameter(request, "idCardName"));
			log.setIdCardNo(RequestUtil.getParameter(request, "idCardNo"));
			log.setProvince(RequestUtil.getParameter(request, "province"));
			log.setCity(RequestUtil.getParameter(request, "city"));
			log.setDistrict(RequestUtil.getParameter(request, "district"));
			log.setStreet(RequestUtil.getParameter(request, "street"));
			log.setOccupation(RequestUtil.getParameter(request, "occupation"));
			log.setJob(RequestUtil.getParameter(request, "job"));
			log.setCompany(RequestUtil.getParameter(request, "company"));
			log.setWorkTime(RequestUtil.getParameter(request, "workTime"));
			log.setSchoolteachingExperience(RequestUtil.getParameter(request, "schoolteachingExperience"));
			log.setAuditStatus(member.getAuditStatus());
		
			if (RequestUtil.getParameter(request, "sex") != null) {
				if (RequestUtil.getParameter(request, "sex").equals("1")) {
					log.setSex("男");
				} else {
					log.setSex("女");
				}
			}
			if (RequestUtil.getParameter(request, "isHadTeacherCertification") != null) {
				if (RequestUtil.getParameter(request, "isHadTeacherCertification").equals("1")) {
					log.setIsHadTeacherCertification(true);
				} else {
					log.setIsHadTeacherCertification(false);
				}
			}
		
			Date createTime = new Date();
		
			// 上传处理
			Map<Integer, UploadInfoEntity> map = UploadDownloadUtil.uploadAction(request, session,
					UploadFileType.APPLY.getValue(), createTime);
			if (null != map && map.size() != 0) {
		
				String filename = "";
				if (StringUtils.isEmpty(map.get(1)) == false) {
					filename = log.getIdCardFrontUrl();
					if (StringUtils.isEmpty(filename) == false) {
						UploadDownloadUtil.deleteAction(filename);
					}
					log.setIdCardFrontUrl(map.get(1).getFileUrl());
				}
				if (StringUtils.isEmpty(map.get(2)) == false) {
					filename = log.getIdCardBackUrl();
					if (StringUtils.isEmpty(filename) == false) {
						UploadDownloadUtil.deleteAction(filename);
					}
					log.setIdCardBackUrl(map.get(2).getFileUrl());
				}
				if (StringUtils.isEmpty(map.get(3)) == false) {
					filename = log.getPersonalHandheldIdCardUrl();
					if (StringUtils.isEmpty(filename) == false) {
						UploadDownloadUtil.deleteAction(filename);
					}
					log.setPersonalHandheldIdCardUrl(map.get(3).getFileUrl());
				}
				if (StringUtils.isEmpty(map.get(4)) == false) {
					filename = log.getLessonVideoUrl();
					if (StringUtils.isEmpty(filename) == false) {
						UploadDownloadUtil.deleteAction(filename);
					}
					log.setLessonVideoUrl(map.get(4).getFileUrl());
				}
			}
			log.setCreateTime(createTime);
		
			// 新增审核流程
			AuditProcessLog auditProcessLog = new AuditProcessLog();
			auditProcessLog.setName(AuditStatus.getString(AuditStatus.WAIT_AUDIT.getValue()));
			auditProcessLog.setType(AuditStatus.WAIT_AUDIT.getValue());
			auditProcessLog.setSort(1);
			auditProcessLog.setTargetSn(member.getSn());
			auditProcessLog.setTargetType(AuditProcessType.TEACHER_INFO.getValue());
			auditProcessLog.setAuditStatus(AuditStatus.WAIT_AUDIT.getValue());
			auditProcessLog.setCreateTime(createTime);
			auditProcessLogService.insert(auditProcessLog);
		
			// 保存数据库
			memberInfoService.updateById(member);
			teacherApplyInfoLogService.insert(log);
			session.setAttribute(ConstantUtil.SESSION_RETURN_URL, "/member/auth/authAuditing.html");
			AuthController.initSession(session, member);
			result.setIsSuccess(true);
		} catch (Exception e) {
			result.setMessage(ErrorMessageUtil.SYSTEM_ERROR);
			log.error(e.getMessage(), e);
		}
		return result;
		
		}*/

}